--
-- Author: mm
-- Date: 2018-05-08 10:53:40
--
-- ItemGotWayView
-- 物品获取途径UI

local ItemGotWayRender = import(".renders.ItemGotWayRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.ItemGotWayUi

local string_split = string.split

function ClassRef:init()
    display.setCascadeOpacityEnabled(self._root, true)
	self._ui.Button_ok:addClickEventListener(function()
        -- executeFunc( self._onCloseView, self )
        self:closeView()
	end)

	self._ui.ListView.createRender = function (list, idx)
		local items = list:getItems()
		local render = items[idx]
		if nil == render then
			render = ItemGotWayRender.create()
			list:pushBackCustomItem(render)
		end
		render:setVisible(true)
		-- 设置回调处理函数
        render:onBtnClick( function( op, data )
            if data then
                display.resourceGotoFeature(data)
            end
            executeFunc( self._onCloseView, self )
		end )
		return render
	end

	display.nodeRemoveForNotHit(self._ui.Panel, function()
        -- executeFunc( self._onCloseView, self )
        self:closeView()
	end)
end

-- 刷新内容
-- dataTemp = DB.getResource
function ClassRef:refreshContent( dataTemp )
	local memberList = string_split( dataTemp, ";" )
    local len = #memberList
    local curIdx = 0
    local function addGuildMemberInfo()
        curIdx = curIdx + 1
        if curIdx <= len then
            local render = self._ui.ListView:createRender(curIdx)
            render:setData(memberList[curIdx])
        else
            --删掉多余的item
            display.removeListUnuseItem(self._ui.ListView, len)
            self._ui.ListView:stopAllActions()
        end
    end
    if len > 0 then
        local items = self._ui.ListView:getItems()
        for i,item in ipairs(items) do
            item:setVisible(false)
        end
        self._ui.ListView:setVisible(true)
        self._ui.ListView:schedule(addGuildMemberInfo, 0)
    else
        self._ui.ListView:setVisible(false)
    end
end


return ClassRef
